<template>
  <div>
    <div>

    </div>
    <div class="shop_top">
      <!-- //状态查询下拉框 -->
      <el-select v-model="shopStat1" placeholder="请选择" style="position: absolute;left: 0px;">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>

      <el-input placeholder="根据联系人,电话,店名查询" v-model="likeName" style="width: 400px; position: absolute; left: 200px;"></el-input>
      <el-button style="position: absolute;left: 650px;" @click="findshopby"  >查询</el-button>
      <el-button style="position: absolute;left: 720px;" @click="addshop"  >新增</el-button>
      <el-button style="position: absolute;left: 800px;" @click="deleshop">删除</el-button>
    </div>

    <div id="" class="table1">
      <el-table :data="shops"
      :row-class-name="tableRowClassName"
       @selection-change="handleSelectionChange">
        <!-- 表格中多选框组件 -->
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="shopCode" label="序列号" width="140">
        </el-table-column>
        <el-table-column prop="shopName" label="门店名称" width="120">
        </el-table-column>
        <el-table-column prop="contact" label="联系人" width="120">
        </el-table-column>
        <el-table-column prop="phoneNo" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="address" label="门店地址" width="120">
        </el-table-column>
        <el-table-column prop="whName" label="管辖仓库" width="120">
        </el-table-column>
        <el-table-column prop="shopStat" :formatter="IsKill" label="门店状态" width="120">
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button @click="updateshop(scope.row)" type="text" size="small">修改门店信息</el-button>
          </template>
        </el-table-column>
      </el-table>


      <!-- //分页插件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page.sync="pages.current" :page-size="pages.size" layout="total, prev, pager, next"
        :total="pages.total">
      </el-pagination>
      <!-- 修改店铺弹框 -->
      <el-dialog title="修改门店" :visible.sync="updateShopFormVisible" @close="warClose">
             <el-form  label-width="80px">
               <el-form-item label="门店编号">
               	<el-input v-model="shop.shopCode" disabled="disabled"></el-input>
               </el-form-item>
           		<el-form-item label="门店名称">
           			<el-input v-model="shop.shopName"></el-input>
           		</el-form-item>
           		<el-form-item label="负责人">
           			<el-input v-model="shop.contact"></el-input>
           		</el-form-item>
               <el-form-item label="联系方式">
               	<el-input v-model="shop.phoneNo"></el-input>
               </el-form-item>
               <el-form-item label="地址">
               	<el-input v-model="shop.address"></el-input>
               </el-form-item>
               <el-form-item label="关联的门店">
               	<el-input v-model="shop.whName" disabled="disabled"></el-input>
               </el-form-item>
               <el-form-item label="状态">
               	<template>
               	  <el-radio v-model="shop.shopStat" label="1">启用</el-radio>
               	  <el-radio v-model="shop.shopStat" label="0">禁用</el-radio>
               	</template>
               </el-form-item>
              </el-form>
             <div slot="footer" class="dialog-footer">
               <el-button @click="updateShopFormVisible = false">取 消</el-button>
               <el-button type="primary" @click="updateWarOK">保存</el-button>
             </div>
           </el-dialog>

           <!-- 新增门店 弹框-->
           <el-dialog title="新增门店" :visible.sync="addShopFormVisible" @close="shopClose">
                  <el-form  label-width="80px">
                    <el-form-item label="门店编号" >
                    	<el-input v-model="shop.shopCode" disabled="disabled" ></el-input>
                    </el-form-item>
                		<el-form-item label="门店名称"placeholder="长度不小于3">
                			<el-input v-model="shop.shopName"></el-input>
                		</el-form-item>
                		<el-form-item label="负责人">
                			<el-input v-model="shop.contact"></el-input>
                		</el-form-item>
                    <el-form-item label="联系方式"placeholder="长度在11到13位数">
                    	<el-input v-model="shop.phoneNo"></el-input>
                    </el-form-item>
                    <el-form-item label="地址">
                    	<el-input v-model="shop.address"></el-input>
                    </el-form-item>
                    <el-form-item label="状态">
                    	<template>
                    	  <el-radio v-model="shop.shopStat" label="1">启用</el-radio>
                    	  <el-radio v-model="shop.shopStat" label="0">禁用</el-radio>
                    	</template>
                    </el-form-item>


                   </el-form>
                  <!-- 多选框 -->
                    <el-checkbox-group v-model="Chankwarehouse" >
                      <el-checkbox v-for="item in warehouse" :label="item.whCode" :key="item.whCode">{{item.whName}}</el-checkbox>
                    </el-checkbox-group>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="addShopFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addshopOk">添加</el-button>
                  </div>
                </el-dialog>
    </div>


  </div>
</template>

<script>
  export default {
    name: 'shop',
    data() {
      return {
        options: [{
          value: '',
          label: '全部'
        }, {
          value: '1',
          label: '正在营业'
        }, {
          value: '0',
          label: '未营业',
        }],
        likeName:"",
        shopStat1: '',
        shops: [],
        shop: {
          shopCode: "",
          shopName: "",
          contact: "",
          phoneNo: "",
          address: "",
          shopStat: "",
          whName: "",
        },
        current: "",
        size: "",
        pages: null,
        multipleSelection:[],
        updateShopFormVisible:false,
        findWarStore:{},
        addShopFormVisible:false,
        warehouse:[],
        Chankwarehouse:[],
      }
    },
    methods: {

      //新增店铺
      addshopOk(){

            this.$http.post("/pawnShop/addShop",{
              shopCode:this.shop.shopCode,
              shopName:this.shop.shopName,
              contact:this.shop.contact,
              phoneNo:this.shop.phoneNo,
              address:this.shop.address,
              shopStat:this.shop.shopStat,
              whCode:this.Chankwarehouse
            }).then(resp=>{
              alert(resp.data.message)
              this.addShopFormVisible=false;
              location.reload();
            })
         this.addShopFormVisible=false;
      },
      addshop(){

        this.$http.get("/pawnWarehouse/getAllwh").then(resp=>{
          this.warehouse=resp.data.data
          console.log(this.warehouse)
        })
       this.addShopFormVisible=true;
      },
      // 修改店铺信息
      updateshop(shop){
        this.shop=shop
        this.updateShopFormVisible=true;
      },
      shopClose(){
           this.addShopFormVisible=false;
      },
      warClose(){
         this.updateShopFormVisible=false;
      },
      updateWarOK(){
        this.$http.post("/pawnShop/updateShop",{shopform :this.shop}).then(resp=>{
          this.shop={};
          this.updateShopFormVisible=false;
          alert(resp.data.message);

        })
      },
      getAllshops(current, size) {
        this.$http.get("/pawnShop/findAllshop", {
          params: {
            current: current,
            size: size
          }
        }).then(resp => {
          this.shops = resp.data.data.records
          this.pages = resp.data.data
          this.current = resp.data.data.current
          this.size = resp.data.data.size
          // this.whName = resp
        })
      },
      // 多选框选择赋值
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      findshopby(){
        this.findshopbylike(1,4)
      },
      // 删除店铺
      deleshop(){
          this.$http.post("/pawnShop/delShopById",{listshops:this.multipleSelection}).then(resp=>{
            alert(resp.data.message)
            location.reload();
          })
      },
      // 模糊查询店铺
      findshopbylike(current,size){
        this.$http.get("/pawnShop/getShopByLike",{
          params: {
            current:current,
            size: size,
            shopStat:this.shopStat1,
            likeName:this.likeName
          }
        }).then(resp=>{
          console.log(resp)
          this.shops = resp.data.data.records
          this.pages = resp.data.data
          this.current = resp.data.data.current
          this.size = resp.data.data.size
          // this.whName = resp
        })
      },

      tableRowClassName({
        row,
        rowIndex
      }) {
        if (row.shopStat == 0) {
          return 'warning-row'
        }
      },
      IsKill(row, column) {
        if (row.shopStat == 1) {
          return "营业中"
        } else {
          return "停业"
        }
      },
      // 分页方法
      handleSizeChange(size) {
        if(this.likeName==""&&this.shopStat1==""){
           this.getAllshops(this.current, size)
        }else{
           this.findshopbylike(this.current, size);
        }
      },
      handleCurrentChange(current) {
        if(this.likeName==""&&this.shopStat1==""){
           this.getAllshops(current, this.size)
        }else{
             this.findshopbylike(current,this.size);
        }
      },
    },
    created() {
      this.getAllshops(1, 4);
    },
    watch:{
      'shopStat1':function(){
         this.findshopbylike(1,4);
      },
      'likeName':function(){
         this.findshopbylike(1,4);
      }
    }
  }
</script>

<style>
  .el-table .warning-row {
    background: yellow;
  }

  .shop_top {
    position: absolute;
    height: 50px;
    width: 1030px;
    left: 150px;
    top:0px;
    background-color: skyblue;
  }

  .table1 {
    position: absolute;
    top: 50px;
    left: 150px;
  }
</style>
